package com.ui;

import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class Admin_Cen extends JDialog {
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;
    private JButton Button_X;
    private JButton Button_pur;
    private JButton Button_add;
    private JButton Button_up;

    public Admin_Cen() {
        setContentPane(contentPane);
        setModal(true);
        getRootPane().setDefaultButton(buttonOK);

//        buttonOK.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//                onOK();
//            }
//        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // 点击 X 时调用 onCancel()
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // 遇到 ESCAPE 时调用 onCancel()
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        Button_X.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Open_x();
            }
        });
        Button_pur.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Open_pur_history();
            }
        });
        Button_add.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Open_update_X();
            }
        });
        Button_up.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Open_x_numup();
            }
        });
    }
    private void Open_x_numup(){new X_num_update().main();}
    private void Open_update_X(){
        new X_update().main();
    }
    private void Open_pur_history(){
        new ALL_pur_history().main();
    }
    private void Open_x(){
        new ALL_x().main();
    }

//    private void onOK() {
//        // 在此处添加您的代码
//        dispose();
//    }

    private void onCancel() {
        // 必要时在此处添加您的代码
        dispose();
    }

    public void main() {
        Admin_Cen dialog = new Admin_Cen();
        dialog.pack();
        dialog.setVisible(true);
        System.exit(0);
    }
}
